package com.fh.shop.admin.controller.area;

import com.fh.shop.admin.common.ServerResponse;
import com.fh.shop.admin.biz.area.IAreaService;
import com.fh.shop.admin.po.area.Area;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/area")
public class AreaController {
    @Resource(name = "areaService")
    private IAreaService areaService;

    @GetMapping("/toIndex")
    public String toIndex(){
        return "area/index";
    }

    //列表
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse list(){
        return areaService.findAreaList();
    }

    //增加
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse add(Area area){
        return areaService.addArea(area);
    }

    //删除
    @RequestMapping(value = "/deleteBatch",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse deleteBatch(String ids){
        return areaService.deleteBatchArea(ids);
    }

    //回填
    @RequestMapping(value = "/findArea",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse findArea(Long id){
        return areaService.findArea(id);
    }

    //修改
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse update(Area area){
        return areaService.updateArea(area);
    }

    //根据父级id查询省市区
    @RequestMapping(value = "findAreaByFatherId",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse findAreaByFatherId(Long id){
        return areaService.findAreaByFatherId(id);
    }

}
